//
//  ViewController.m
//  CAGradientLayer~demo1
//
//  Created by 石虎 on 2017/9/5.
//  Copyright © 2017年 石虎. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CAGradientLayer *colorLayer = [CAGradientLayer layer];
    colorLayer.frame    = (CGRect){CGPointZero, CGSizeMake(400, 600)};
    colorLayer.position = self.view.center;
    [self.view.layer addSublayer:colorLayer];
    
    // 颜色分配
    colorLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,
                          (__bridge id)[UIColor greenColor].CGColor,
                         
                          (__bridge id)[UIColor orangeColor].CGColor,
                          (__bridge id)[UIColor yellowColor].CGColor,
                          
                          (__bridge id)[UIColor magentaColor].CGColor,
                          (__bridge id)[UIColor purpleColor].CGColor,
                          
                          (__bridge id)[UIColor brownColor].CGColor,
                          (__bridge id)[UIColor blueColor].CGColor];
    
    // 颜色分割线
    colorLayer.locations  = @[@(0.15), @(0.3), @(0.45),@(0.55),@(0.65),@(0.75)];
    
    // 起始点
    colorLayer.startPoint = CGPointMake(0, 0);
    
    // 结束点(垂直)
    //colorLayer.endPoint   = CGPointMake(1, 0);
    
     // 结束点(45度)
    colorLayer.endPoint   = CGPointMake(1, 1);
}

@end
